define(
    function (require) {
        require('tpl!./list.tpl.html');

        var u = require('underscore');

        var fields = [
            {
                title: '编号',
                field: 'id' ,
                sortable: true,
                resizable: true,
                width: 20,
                content: function (item) {
                    return item.id;
                }
            },
            {
                title: '新品头图',
                field: 'titlePic' ,
                resizable : true,
                width: 120,
                content: function (item) {
                    return [
                        '<img src="' + item.titlePic + '" width="100" />'
                    ].join('');
                }
            },
            {
                title: '新品名称',
                field: 'name' ,
                resizable : true,
                width: 100,
                content: function (item) {
                    return [
                        '<span class="list-link" data-command-args="'
                            + item.id
                            + '" data-command="modify">'
                            + item.name
                            + '</a>'
                    ].join('');
                }
            },
            {
                title: '现价',
                field: 'price' ,
                width: 100,
                content: function (item) {
                    return item.price;
                }
            },
            {
                title: '原价',
                field: 'oldPrice' ,
                width: 100,
                content: function (item) {
                    return item.oldPrice;
                }
            },
            {
                title: '操作',
                field: 'operate' ,
                width: 60,
                content: function (item) {
                    var operates = [
                        '<span class="list-link" data-command-args="'
                            + item.id
                            + '" data-command="modify">修改</a></span>',
                        '<span class="list-link" data-command-args="'
                            + item.id
                            + '" data-command="delete">删除</a></span>'
                    ];
                    return operates.join('');
                }
            }
        ];

        var BaseListView = require('common/ListView');

        function ListView() {
            BaseListView.apply(this, arguments);
        }

        ListView.prototype.template = 'shoppingNewProductListPage';

        ListView.prototype.getUIProperties = function () {
            BaseListView.prototype.getUIProperties.apply(this, arguments);
            return {
                list: {
                    fields: fields,
                    sortable: false,
                    columnResizable: true,
                    subrow: false,
                    followHead: true,
                    selectMode: 'line',
                    noDataHtml: '<p style="margin:0;">暂无优惠信息!</p>'
                }
            };
        }


        ListView.prototype.enterDocument = function () {
            BaseListView.prototype.enterDocument.apply(this, arguments);

            var me = this;
            this.get('list').on(
                'command',
                function (event) {
                    me.fire(event.name, event);
                }
            );

            this.get('createButton').on(
                'click',
                this.fire.bind(this, 'create')
            );

            this.get('list').initChildren();
        }

        require('er/util').inherits(ListView, BaseListView);
        return ListView;
    }
);
